package com.codingman.springbootdemo1;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class EmployeeController {
	@GetMapping("/employee/{id}")
	public Employee getEmployee(@PathVariable Integer id) {
		return new Employee(101, "Ann", 100.00);
	}
	
	@PostMapping("/employee")
	public String saveEmployee(@RequestBody Employee emp) {
		return "{\"message\":\"success\", \"name\":" + emp.getName() + "}";
	}
	
	@PutMapping("/employee/{id}")
	public String updateEmployee(@PathVariable Integer id, @RequestBody Employee emp) {
		return "{\"message\":\"success\", \"name\":" + emp.getName() + "}";
	}
	
	@DeleteMapping("/employee/{id}")
	public String deleteEmployee(@PathVariable Integer id) {
		return "{\"message\":\"success\", \"id\":" + id + "}";
	}
}
